import time
from loguru import logger
from src.settings import setting


def get_logger():
    log_path = setting.BASE_DIR.joinpath('logs')
    log_path.mkdir(parents=True, exist_ok=True)

    log_path_info = log_path.joinpath(f"info_{time.strftime('%Y-%m-%d')}.log")
    log_path_error = log_path.joinpath(f"error_{time.strftime('%Y-%m-%d')}.log")

    logger.add(
        log_path_info,
        rotation="00:00",
        retention="3 days",
        mode='a+',
        encoding="utf-8",
        level="INFO",
        format="{name}:{function}:{line} | {message}"
    )

    logger.add(
        log_path_error,
        rotation="500 MB",
        retention="4 weeks",
        mode='a+',
        encoding="utf-8",
        level="ERROR",
        format="{time:YYYY-MM-DD HH:mm:ss.SSS} | {level} |{name}:{function}:{line} | {message}"
    )
    return logger


get_logger()
